//
//  UILabel+Extension.swift
//  SinaWeibo
//
//  Created by 林柱强 on 16/2/3.
//  Copyright © 2016年 林柱强. All rights reserved.
//

import UIKit

extension UILabel {
    //1.>文字
    //2.>文字大小
    //3.>文字的颜色
    
    //参数指定默认值  该参数 可以不传
    convenience init(title: String, size: CGFloat, color: UIColor, margin: CGFloat = 0){
        self.init()
        text = title
        textAlignment = NSTextAlignment.Center
        font = UIFont.systemFontOfSize(size)
        textColor = color
        numberOfLines = 0
        if margin != 0 {
            preferredMaxLayoutWidth = screenWidth - 2 * margin
            textAlignment = .Left
        }
        
        //设置大小
        sizeToFit()
    }
    
    convenience init(title: String, size: CGFloat, textcolor: UIColor, bgColor: UIColor){
        self.init()
        text = title
        textAlignment = NSTextAlignment.Center
        font = UIFont.systemFontOfSize(size)
        textColor = textcolor
        backgroundColor = bgColor
        //设置大小
//        sizeToFit()
    }
    
    /// 快速创建一个UILabel
    class func createLabel(color: UIColor, fontSize: CGFloat) -> UILabel
    {
        let label = UILabel()
        label.textColor = color
        label.font = UIFont.systemFontOfSize(fontSize)
        return label
    }
}
